<template>
  <div class="login-box">
    <h2>师傅登录</h2>
    <input v-model="username" placeholder="用户名" />
    <input v-model="password" type="password" placeholder="密码" />
    <button @click="login">登录</button>
    <p v-if="tip" class="tip">{{ tip }}</p>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import axios from 'axios'

const username = ref('')
const password = ref('')
const tip      = ref('')

async function login() {
  tip.value = ''
  try {
    // 使用代理路径，Vite 会自动转发到 http://localhost:8080
    const { data: token } = await axios.post('/base/login/pwd', {
      username: username.value,
      password: password.value
    })
    localStorage.setItem('token', token)
    tip.value = '登录成功！'
  } catch (e) {
    tip.value = e.response?.data?.message || '账号或密码错误'
  }
}
</script>

<style scoped>
.login-box{width:300px;margin:100px auto;text-align:center}
input,button{display:block;width:100%;margin:8px 0;padding:8px}
.tip{color:crimson}
</style>